package com.wx.datastructure.stack.array;

import com.wx.datastructure.array.MyArray;
import com.wx.datastructure.stack.Stack;

/**
 * @author wx
 * @Description: 线性数据结构-数组类型-栈(先进后出)
 * @date 2018/12/10 001018:21
 */
public class ArrayStack<E> implements Stack<E>{
    private MyArray<E> myArray;


    public ArrayStack() {
        this.myArray = new MyArray<>();
    }

    public ArrayStack(int length) {
        this.myArray = new MyArray<>(length);
    }

    @Override
    public int size() {
        return this.myArray.size();
    }

    @Override
    public boolean isEmpty() {
        return this.myArray.isEmpty();
    }

    @Override
    public void push(E e) {
        this.myArray.addLast(e);
    }

    @Override
    public E pop() {
        return this.myArray.removeLast();
    }

    @Override
    public E peek() {
        return this.myArray.getLast();
    }
}
